package com.hashTable;

import java.util.HashSet;

public class HappyNumber0131_202 {
    public boolean isHappy(int n) {
        HashSet<Integer> set = new HashSet<>();

        while (!set.contains(n) && n!=1){
            set.add(n);
            int sum = 0;
            while (n > 0) {
                int i = n%10;
                sum += i*i;
                n = n/10;
            }
            n = sum;
        }
        return n==1;
    }
}
